﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using UsedBookTradeSystem.DBContext;

namespace UsedBookTradeSystem.Controllers.FrontControllers
{
    public class ShopBookController : Controller
    {
        private readonly SystemDbContext _ctx;

        public ShopBookController(SystemDbContext ctx)
        {
            _ctx = ctx;
        }

        [Authorize(Roles = "User")]
        public async Task<IActionResult> Detail(int id)
        {
            var BookDetail = await _ctx.BooksInfo.Include(x=>x.Category).FirstOrDefaultAsync(x => x.Id == id);
            if (BookDetail == null) 
            {
                TempData["OperateResult"] = "书籍id不存在！";
                return RedirectToAction(nameof(Index));
            }
            ViewBag.BookDetail = BookDetail;
            return View();
        }
    }
}
